package org.example.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 通过设置属性consumeMode = ConsumeMode.ORDERLY，指定消费模式为顺序消费，消费的顺序也和发送顺序一致
 *
 * @author : Charles
 * @date : 2021/6/10
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = "order_topic",
        consumeMode = ConsumeMode.ORDERLY,//指定为顺序消费
        consumerGroup = "order_group")
public class OrderListener implements RocketMQListener<String> {
    @Override
    public void onMessage(String message) {
        //发送消息是顺序发送的0,1,2,3,消费的顺序也是顺序的
        log.info("{}收到消息：{}", this.getClass().getSimpleName(), message);
    }

}
